{layout name="layout/header" /}
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="root/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="root/css/plugins/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet">
<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{$title}</h5>
                </div>
                <!--<div class="ibox-content">-->
                    <!--<p>-->
                        <!--<button type="button" class="btn btn-primary btn-outline refresh">刷新</button>-->
                        <!--<a type="button" class="btn btn-primary btn-outline" href="{:url('index')}">返回列表页</a>-->
                    <!--</p>-->
                <!--</div>-->
                <div class="ibox-content">
                    <form class="form-horizontal" id="form">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" v-model="title" name="title">

                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-2 control-label">显示</label>
                            <div class="col-sm-10" >
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="display" value="1" name="display"> <i></i>正常</label>
                                    <label><input type="radio" v-model="display" value="0" name="display"> <i></i>隐藏</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">跳转链接</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" v-model="link" name="link">
                                <span class="help-block m-b-none">如果无跳转，请不要填此项</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" v-model="sort" name="sort">
                                <span class="help-block m-b-none">默认0按时间倒序排序，如果大于0，则按数字大小倒序置顶</span>
                            </div>
                        </div>
                        <!--图片上传-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片</label>
                            <div class="col-sm-10">
                                <button class="btn btn-success product_upload_img" type="button">
                                    <i class="fa fa-upload"></i>&nbsp;&nbsp;<span class="bold">上传</span>
                                </button>
                                <input class="vue_img" type="file" style="display: none;" data-field="img"/>
                                <!--<span class="help-block m-b-none">比例612px*816px</span>-->

                            </div>
                            <div class="col-sm-10 col-sm-offset-2 ">
                                <div class="row" id="img">
                                    <div class="img_box col-xs-12 col-md-3" v-if="img!=''">
                                        <a class="fancybox" :href="img">
                                            <img alt="image" :src="img"/>
                                        </a>
                                        <a class="glyphicon glyphicon-trash" onclick="del_wx_img(this,'img');"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-primary" @click="submit" type="submit">保存内容</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>
<script src="root/js/plugins/fancybox/jquery.fancybox.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script>
    var data = {$data};
    var url = "{$url}";

    if (data == 1) {
        data = {
            id: 0,
            title:'',
            img:'',
            display:1,
            sort:0,
            link:'',
        }
    }
    //1

    new Vue({
        el: "#app",
        data: data,
        methods: {
            submit:function () {
                $("#form").validate({
                    rules:{
                        title:{
                            required:true,
                        },
                        sort:{
                            digits:true,
                        }
                    },
                    messages:{

                    }
                })
                if($("#form").valid()) {
                    if(this.img == ''){
                        layer.msg('图片不能未空');
                        return ;
                    }
                    $.post(url,data,function (res) {
                        layer.msg(res.msg);

                        if(res.code==1){
                            setTimeout(function () {
                                window.location.reload()
                            },1500)
                        }
                    },'json')
                }

            }
        },
        mounted: function () {
            checks();
            $('.fancybox').fancybox({
                openEffect: 'none',
                closeEffect: 'none'
            });
            $('.datetimepicker').datetimepicker({
                format:'yyyy-mm-dd hh:ii',
                language:  'zh-CN',
                weekStart: 1,
                todayBtn:  1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                forceParse: 0,
            });
        }
    });
</script>

<script>
    $('input[name="display"]').on('ifChecked', function (event) {
        data.display = $(this).val()
    });

</script>
